package com.ganinfo.common.data;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;

/**
 * @ClassName:   OtherDataUtil
 * @Description: T其他数据工具类
 * @author:      ruikanwang
 * @date:        2017年3月1日 下午4:56:12
 */
public class OtherDataUtil {
	public static final String allChar = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	public static final String letterChar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	public static final String upperLetterChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	public static final String lowerLetterChar = "abcdefghijklmnopqrstuvwxyz";
	public static final String numberChar = "0123456789";
	public static final String numberLowerLetterChar = "0123456789abcdefghijklmnopqrstuvwxyz";
	public static final String numberUpperLetterChar = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	
	/**
	 * @Title:       get32UUID
	 * @Description: 获取32位uuid
	 * @return
	 * @return:      String
	 */
	public static String get32UUID() {
		String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
		return uuid;
	}
	
	public static String getRandomALLChar(int n) {
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		for(int i = 0; i < n; i++) {
			sb.append( allChar.charAt( random.nextInt( allChar.length() ) ) );
		}
		return sb.toString();
	}
	
	public static String getRandomLetterChar(int n) {
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		for(int i = 0; i < n; i++) {
			sb.append( letterChar.charAt( random.nextInt( letterChar.length() ) ) );
		}
		return sb.toString();
	}
	
	public static String getRandomUpperLetterChar(int n) {
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		for(int i = 0; i < n; i++) {
			sb.append( upperLetterChar.charAt( random.nextInt( upperLetterChar.length() ) ) );
		}
		return sb.toString();
	}
	
	public static String getRandomLowerLetterChar(int n) {
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		for(int i = 0; i < n; i++) {
			sb.append( lowerLetterChar.charAt( random.nextInt( lowerLetterChar.length() ) ) );
		}
		return sb.toString();
	}
	
	public static String getRandomNumberChar(int n) {
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		for(int i = 0; i < n; i++) {
			sb.append( numberChar.charAt( random.nextInt( numberChar.length() ) ) );
		}
		return sb.toString();
	}
	
	public static String getRandomNumberLowerLetterChar(int n) {
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		for(int i = 0; i < n; i++) {
			sb.append( numberLowerLetterChar.charAt( random.nextInt( numberLowerLetterChar.length() ) ) );
		}
		return sb.toString();
	}
	
	public static String getRandomNumberUpperLetterChar(int n) {
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		for(int i = 0; i < n; i++) {
			sb.append( numberUpperLetterChar.charAt( random.nextInt( numberUpperLetterChar.length() ) ) );
		}
		return sb.toString();
	}
	public static void main1(String[] args) {
		int k = 3;
		int p = 2;
		System.out.println("---------------------------------------------------全部字符------");
		for(int i = 0; i < k; i++) {
			System.out.println("getRandomAllChar(): " + i + " -------");
			System.out.println(getRandomALLChar(p));
		}
		
		System.out.println("------------------------------------------------字母字符---------");
		for(int i = 0; i < k; i++) {
			System.out.println("getRandomLetterChar(): " + i + " -------");
			System.out.println(getRandomLetterChar(p));
		}
		
		System.out.println("-------------------------------------------------大写字母字符--------");
		for(int i = 0; i < k; i++) {
			System.out.println("getRandomUpperLetterChar(): " + i + " -------");
			System.out.println(getRandomUpperLetterChar(p));
		}
		
		System.out.println("-------------------------------------------------小写字母字符--------");
		for(int i = 0; i < k; i++) {
			System.out.println("getRandomLowerLetterChar(): " + i + " -------");
			System.out.println(getRandomLowerLetterChar(p));
		}
		
		System.out.println("------------------------------------------------数字字符---------");
		for(int i = 0; i < k; i++) {
			System.out.println("getRandomNumberChar(): " + i + " -------");
			System.out.println(getRandomNumberChar(p));
		}
		
		System.out.println("-----------------------------------------------数字加大写字母字符----------");
		for(int i = 0; i < k; i++) {
			System.out.println("getRandomNumberUpperLetterChar(): " + i + " -------");
			System.out.println(getRandomNumberUpperLetterChar(p));
		}
		
		System.out.println("------------------------------------------------数字加小写字母字符---------");
		for(int i = 0; i < k; i++) {
			System.out.println("getRandomNumberLowerLetterChar(): " + i + " -------");
			System.out.println(getRandomNumberLowerLetterChar(p));
		}
	}
	
	/**
	 * @Title:       getAppointmentNum
	 * @Description: 根据号源数和已预约号返回一个随机数
	 * @param appointmentTotal
	 * @param appointments
	 * @return
	 * @return:      int
	 */
	public static String getAppointmentNum(int appointmentTotal,String appointments){
		if("".equals(appointments)){
			Random rand = new Random();
			int randNum = rand.nextInt(appointmentTotal+1);
			return String.valueOf(randNum);
		}
		
		
		String resultString=null;
		String[] split = appointments.split(",");
		List<Integer> nowintegers=new ArrayList<>();
		for (String string : split) {
			if(!"".equals(string)){
				nowintegers.add(Integer.parseInt(string));
			}
		}
		List<Integer> integers=new ArrayList<>();
		for (int i = 0; i < appointmentTotal; ++i){
			if(!nowintegers.contains(i + 1)){
				integers.add(i + 1);
			}
        }
		if(integers.size()==0){
			
		}else{
			//产生0-(arr.length-1)的整数值,也是数组的索引
			int index=(int)(Math.random()*integers.size());
			resultString =integers.get(index).toString();
		}
		return resultString;
	}
	
	public static void main(String[] args) {
		OtherDataUtil.getAppointmentNum(50, "12,23,7,9,87,32,32,45");
	}
	
	
}
